*This file creates the tables and figures for Appendix L
********************************************************************************
* TABLE L.1, L.2 and FIGURE L.1
********************************************************************************
u $datadir/analysis_cz, clear

eststo clear 
rename present_ru present
bys id_win ru_limit: g n=_n

label var diff_corp_tax "$\Delta$ Corporate Tax (\%)"
label var diff_income_tax "$\Delta$ Income Tax (\%)"
label var diff_sales_tax "$\Delta$ Sales Tax (\%)"
label var diff_proptax "$\Delta$ Property Tax (\%)"
label var diff_FHFA "$\Delta$ Housing Price (\\$1,000)"
label var diff_wage "$\Delta$ Industry Wage (\\$1,000)"
label var diff_incwage "$\Delta$ Industry Wage (\\$1,000)"
label var diff_e_ind "$\Delta$ Industrial Electricity Price (c/KwH)"
label var diff_e_comm "$\Delta$ Commercial Electricity Price (c/KwH)"
label var diff_indus_zoning "$\Delta$ Perceived Industrial Land Supply"
label var diff_r2w "$\Delta$ Right-to-Work State"
label var diff_bad_bridges "$\Delta$ Poor Condition Bridges (\%)"
label var diff_auto_roadnetwork "$\Delta$ Auto Network Density"
label var diff_freightrail "$\Delta$ Freight Rail Density"
label var diff_airport_any "$\Delta$ Large Airport"
label var diff_occ_top2_naics3 "$\Delta$ Population in Relevant Occupations (1,000)"
label var diff_pr_college "$\Delta$ Population with BA+ (\%)"
label var diff_perc_est_n4 "$\Delta$ Industry Establishment Share (\%)"
label var diff_top_RD "$\Delta$ Research University" 

label var jobs_direct "Jobs Promised (1,000)"
label var corp_tax "Corporate Tax (\%)"
label var income_tax "Income Tax (\%)"
label var sales_tax "Sales Tax (\%)"
label var proptax "Property Tax (\%)"
label var mult_supp "Industry Multipler"
label var invest_B "Investment Planned (\\$ B)"
label var unemp "Unemployment Rate (\%)"
label var incwage_top_5 "Relevant Occupation Wage (\\$1,000)"
label var term_limit "Term-limited Governor"
label var min_mindist "Distance to State Border"
label var present "Firm Presence in Runner-up Location"
label var density "Population (1,000) per Mile"
label var mult_jobs "Indirect Jobs (Jobs $\times$ Multiplier)"
label var ln_pinc  "Log(Personal Income per Capita)"
label var mult_tot "Industry Multiplier"

eststo clear 

************ORIGINAL 
eststo:  reg sub_M ///
c.diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax c.diff_proptax   /// taxes
diff_wage   c.diff_e_ind#c.invest_B  /// costs
 c.diff_indus_zoning#c.invest_B /// regulations 
c.diff_auto_roadnetwork#3.manuf_type  /// logistics/infrastructure 
diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct c.diff_pr_college#i.manuf_type /// skilled labor 
c.diff_perc_est_n4#1.manuf_type /// agglomeration/suppliers
jobs_direct c.mult_jobs invest_B income_tax corp_tax term_limit unemp c.unemp#c.jobs_direct c.ln_pinc c.incwage_top_5 ///
c.incwage_top_5#c.ln_pinc [pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000, noconstant robust
estadd scalar obs = 200

foreach v in income_tax corp_tax term_limit ///
 unemp incwage_top_5 ln_pinc {
 	g `v'_ru = `v'
	drop `v'
	rename `v'_win `v'
 }
 
 predict resid_v1, r 
 g v2_v1 = _b[jobs_direct]*jobs_direct + _b[mult_jobs]*mult_jobs + _b[invest_B]*invest_B ///
	+ _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[c.unemp#c.jobs_direct]*unemp_ru*jobs_direct ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
		+ _b[ln_pinc]*ln_pinc_ru ///
	+ _b[c.incwage_top_5#c.ln_pinc]*incwage_top_5_ru*ln_pinc_ru
	
summ jobs_direct if e(sample)==1
local mj = `r(mean)'
summ invest_B if e(sample)==1 
local mi = `r(mean)'
summ mult_jobs if e(sample)==1
local mm = `r(mean)'
	
 g v2_v1_noz = 	 _b[jobs_direct]*`mj' + _b[mult_jobs]*`mm' + _b[invest_B]*`mi' ///
    + _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[c.unemp#c.jobs_direct]*unemp_ru*`mj' ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
		+ _b[ln_pinc]*ln_pinc_ru ///
	+ _b[c.incwage_top_5#c.ln_pinc]*incwage_top_5_ru*ln_pinc_ru


	
 label var jobs_direct "Jobs Promised (1,000)"
label var corp_tax "Corporate Tax (\%)"
label var income_tax "Income Tax (\%)"
label var sales_tax "Sales Tax (\%)"
label var proptax "Property Tax (\%)"
label var mult_supp "Industry Multipler"
label var invest_B "Investment Planned (\\$ B)"
label var unemp "Unemployment Rate (\%)"
label var incwage_top_5 "Relevant Occupation Wage (\\$1,000)"
label var term_limit "Term-limited Governor"
label var min_mindist "Distance to State Border"
label var present "Firm Presence in Runner-up Location"
label var density "Population (1,000) per Mile"
label var mult_jobs "Indirect Jobs (Jobs $\times$ Multiplier)"
label var ln_pinc  "Log(Personal Income per Capita)"
label var mult_tot "Industry Multiplier"

************USING ONLY WINNING STATE V
eststo:   reg sub_M ///
jobs_direct c.mult_jobs invest_B income_tax corp_tax term_limit ///
 unemp c.unemp#c.jobs_direct c.incwage_top_5 c.ln_pinc ///
c.incwage_top_5#c.ln_pinc [pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000, noconstant robust
estadd scalar obs = 200

************PREDICTING V2 and putting back into original 
g v2_predict = _b[jobs_direct]*jobs_direct + _b[mult_jobs]*mult_jobs + _b[invest_B]*invest_B ///
	+ _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[c.unemp#c.jobs_direct]*unemp_ru*jobs_direct ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
		+ _b[ln_pinc]*ln_pinc_ru ///
	+ _b[c.incwage_top_5#c.ln_pinc]*incwage_top_5_ru*ln_pinc_ru
	
g v2_predict_noz = _b[jobs_direct]*`mj' + _b[mult_jobs]*`mm' + _b[invest_B]*`mi'  ///
    + _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[c.unemp#c.jobs_direct]*unemp_ru*`mj' ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
		+ _b[ln_pinc]*ln_pinc_ru ///
	+ _b[c.incwage_top_5#c.ln_pinc]*incwage_top_5_ru*ln_pinc_ru

foreach v in income_tax corp_tax term_limit ///
 unemp incwage_top_5 ln_pinc {
	rename `v' `v'_win 
	rename `v'_ru `v'
 }
 
 label var jobs_direct "Jobs Promised (1,000)"
label var corp_tax "Corporate Tax (\%)"
label var income_tax "Income Tax (\%)"
label var sales_tax "Sales Tax (\%)"
label var proptax "Property Tax (\%)"
label var mult_supp "Industry Multipler"
label var invest_B "Investment Planned (\\$ B)"
label var unemp "Unemployment Rate (\%)"
label var incwage_top_5 "Relevant Occupation Wage (\\$1,000)"
label var term_limit "Term-limited Governor"
label var min_mindist "Distance to State Border"
label var present "Firm Presence in Runner-up Location"
label var density "Population (1,000) per Mile"
label var mult_jobs "Indirect Jobs (Jobs $\times$ Multiplier)"
label var ln_pinc  "Log(Personal Income per Capita)"
label var mult_tot "Industry Multiplier"

eststo: reg sub_M ///
c.diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax c.diff_proptax   /// taxes
diff_wage   c.diff_e_ind#c.invest_B  /// costs
 c.diff_indus_zoning#c.invest_B /// regulations 
c.diff_auto_roadnetwork#3.manuf_type  /// logistics/infrastructure 
diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct c.diff_pr_college#i.manuf_type /// skilled labor 
c.diff_perc_est_n4#1.manuf_type /// agglomeration/suppliers
v2_predict [pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000, noconstant robust
estadd scalar obs = 200

 predict resid_predict, r
 
 g v2_v1_r = v2_v1 + resid_v1 
 g v2_predict_r = v2_predict + resid_predict

 
preserve
 keep if ru_limit==1 & n==1 & manuf==1 & sub_M<1000
 corr v2_v1 v2_predict
 corr v2_predict_r v2_v1_r
 corr v2_predict_noz v2_v1_noz
 
 g x = 0 in 1
 replace x = 1000 in 200
 
 twoway (scatter v2_v1 v2_predict, m(oh) ) (line x x, lpattern(dash)), xlabel(0(100)1000) ylabel(0(100)1000) ///
 ytitle("predicted using winning characteristics ({c $|}M)") ///
 xtitle("predicted using runner-up characteristics  ({c $|}M)") ///
 legend(off) 
 graph export $appxdir/altspec_v2_manuf.eps, replace 

 replace x = 50 in 1
 replace x = 250 in 200
 
  twoway (scatter v2_v1_noz v2_predict_noz, m(oh) ) (line x x, lpattern(dash)), xlabel(50(50)250) ///
  ylabel(50(50)250) ///
 ytitle("predicted using winning characteristics ({c $|}M)") ///
 xtitle("predicted using runner-up characteristics  ({c $|}M)") ///
  legend(off) 
 graph export $appxdir/altspec_v2_noz_manuf.eps, replace 
 
 restore 
 
esttab using "$appxdir/OLS_manuf_altspec.tex", replace ///
		cells(b(star fmt(%-10.2fc)) & se(par fmt(%-10.2fc))) ///
		stats(obs r2 , fmt(%9.0fc %-10.3fc )	///
		labels( "Observations" "R-squared"))	///
		collabels(none) mlabels(none) label ///
		keep(diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax  /// 
		diff_proptax ///
		 c.diff_indus_zoning#c.invest_B ///
		3.manuf_type#c.diff_auto_roadnetwork ///
		c.diff_e_ind#c.invest_B ///
		diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct  ///
		1.manuf_type#c.diff_pr_college 3.manuf_type#c.diff_pr_college /// 
		1.manuf_type#c.diff_perc_est_n4 ///
		jobs_direct mult_jobs invest_B income_tax corp_tax  term_limit ln_pinc  /// 
		incwage_top_5 unemp c.unemp#c.jobs_direct c.incwage_top_5#c.ln_pinc v2_predict) ///
		order(diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax /// 
		diff_proptax /// 
		diff_wage  c.diff_e_ind#c.invest_B ///
		 c.diff_indus_zoning#c.invest_B ///
		 3.manuf_type#c.diff_auto_roadnetwork ///
		c.diff_e_ind#c.invest_B  ///
		diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct  ///
		1.manuf_type#c.diff_pr_college 3.manuf_type#c.diff_pr_college /// 
		1.manuf_type#c.diff_perc_est_n4  v2_predict ///
		jobs_direct invest_B  mult_jobs income_tax corp_tax  /// 
		ln_pinc  incwage_top_5 c.incwage_top_5#c.ln_pinc  unemp c.unemp#c.jobs_direct term_limit ) ///
		varlabels(c.diff_corp_tax#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			c.diff_e_ind#c.invest_B "$\Delta$ Industrial Electricity Price (c/KwH) $\times$ Investment Planned (\\$ B)" ///
			3.manuf_type#c.diff_auto_roadnetwork "$\Delta$ Auto Network Density $\times$ Traditional Manuf."  ///
			c.diff_indus_zoning#c.invest_B "$\Delta$ Industrial Land Supply $\times$ Investment Planned (\\$ B)" ///
			c.diff_occ_top2_naics3#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ///
			1.manuf_type#c.diff_pr_college "$\Delta$ Population with BA+ (\%) $\times$ High-Tech Manuf."  ///
			3.manuf_type#c.diff_pr_college "$\Delta$ Population with BA+ (\%) $\times$ Traditional Manuf." ///
			1.manuf_type#c.diff_perc_est_n4 "$\Delta$ Industry Estab. Share (\%) $\times$ High-Tech Manuf."  ///
			c.incwage_top_5#c.ln_pinc "\hspace{4mm} $\times$ Log(Personal Income per Capita)" ///
			c.unemp#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ///
			v2_predict "Runner-up Valuation Predicted using Spec (2)") ///
		refcat(diff_corp_tax "\textbf{Profit Function:}" ///
		v2_predict "\textbf{Valuation:}" , nolabel)		 alignment(r)
		
	
drop v2* resid* 

/// NOW DO THE SAME FOR SERVICES 

eststo clear 
************START WITH BASELINE 
eststo: reg sub_M ///
c.diff_corp_tax diff_income_tax c.diff_proptax   /// taxes
 c.diff_income_tax#c.jobs_direct  /// taxes
c.diff_incwage_top_5#i.low_serv diff_FHFA c.diff_FHFA#c.invest_B c.diff_e_comm  /// costs 
 c.diff_r2w /// regulations 
c.diff_auto_roadnetwork c.diff_airport_any#1.trade /// logistics/infrastructure
 c.diff_top_RD#1.trade c.diff_top_RD#0.trade /// skilled labor 
 c.jobs_direct mult_tot  c.invest_B income_tax corp_tax sales_tax proptax term_limit  unemp  incwage_top_5 ln_pinc  [pw=weight] if ru_limit==1 & manuf==0  & sub_M<400, noconstant robust
 estadd scalar obs = 177
 
  predict resid_v1, r 
 
 foreach v in  income_tax corp_tax sales_tax proptax term_limit  unemp  incwage_top_5 ln_pinc  {
 	g `v'_ru = `v'
	drop `v'
	rename `v'_win `v'
 }
 
 
 g v2_v1 = _b[jobs_direct]*jobs_direct + _b[mult_total]*mult_total + _b[invest_B]*invest_B ///
	+ _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[sales_tax]*sales_tax_ru ///
	+ _b[proptax]*proptax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
	+ _b[ln_pinc]*ln_pinc_ru
 
 summ jobs_direct if e(sample)==1
local mj = `r(mean)'
summ invest_B if e(sample)==1 
local mi = `r(mean)'
summ mult_jobs if e(sample)==1
local mm = `r(mean)'
	
 g v2_v1_noz = 	_b[jobs_direct]*`mj' + _b[mult_total]*`mm' + _b[invest_B]*`mi' ///
	+ _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[sales_tax]*sales_tax_ru ///
	+ _b[proptax]*proptax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
	+ _b[ln_pinc]*ln_pinc_ru
	
	
 label var jobs_direct "Jobs Promised (1,000)"
label var corp_tax "Corporate Tax (\%)"
label var income_tax "Income Tax (\%)"
label var sales_tax "Sales Tax (\%)"
label var proptax "Property Tax (\%)"
label var invest_B "Investment Planned (\\$ B)"
label var unemp "Unemployment Rate (\%)"
label var incwage_top_5 "Relevant Occupation Wage (\\$1,000)"
label var term_limit "Term-limited Governor"
label var ln_pinc  "Log(Personal Income per Capita)"
label var mult_total "Industry Multiplier"

************USING ONLY WINNING STATE V
 eststo: reg sub_M ///
 c.jobs_direct mult_tot  c.invest_B income_tax corp_tax sales_tax proptax term_limit  unemp  incwage_top_5 ln_pinc  [pw=weight] if ru_limit==1 & manuf==0  & sub_M<400, noconstant robust
 estadd scalar obs = 177
 
 ***********PREDICTING V2 and putting back into original 
g v2_predict = _b[jobs_direct]*jobs_direct + _b[mult_total]*mult_total + _b[invest_B]*invest_B ///
	+ _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[sales_tax]*sales_tax_ru ///
	+ _b[proptax]*proptax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
	+ _b[ln_pinc]*ln_pinc_ru

g v2_predict_noz = 	_b[jobs_direct]*`mj' + _b[mult_total]*`mm' + _b[invest_B]*`mi' ///
	+ _b[income_tax]*income_tax_ru ///
	+ _b[corp_tax]*corp_tax_ru ///
	+ _b[sales_tax]*sales_tax_ru ///
	+ _b[proptax]*proptax_ru ///
	+ _b[term_limit]*term_limit_ru ///
	+ _b[unemp]*unemp_ru ///
	+ _b[incwage_top_5]*incwage_top_5_ru ///
	+ _b[ln_pinc]*ln_pinc_ru
	
 foreach v in income_tax corp_tax sales_tax proptax term_limit  unemp  incwage_top_5 ln_pinc  {
	rename `v' `v'_win 
	rename `v'_ru `v'
 }
 
 label var jobs_direct "Jobs Promised (1,000)"
label var corp_tax "Corporate Tax (\%)"
label var income_tax "Income Tax (\%)"
label var sales_tax "Sales Tax (\%)"
label var proptax "Property Tax (\%)"
label var invest_B "Investment Planned (\\$ B)"
label var unemp "Unemployment Rate (\%)"
label var incwage_top_5 "Relevant Occupation Wage (\\$1,000)"
label var term_limit "Term-limited Governor"
label var ln_pinc  "Log(Personal Income per Capita)"
label var mult_total "Industry Multiplier"

eststo: reg sub_M ///
c.diff_corp_tax diff_income_tax c.diff_proptax   /// taxes
 c.diff_income_tax#c.jobs_direct  /// taxes
c.diff_incwage_top_5#i.low_serv diff_FHFA c.diff_FHFA#c.invest_B c.diff_e_comm  /// costs 
 c.diff_r2w /// regulations 
c.diff_auto_roadnetwork c.diff_airport_any#1.trade /// logistics/infrastructure
 c.diff_top_RD#1.trade c.diff_top_RD#0.trade /// skilled labor
v2_predict  [pw=weight] if ru_limit==1 & manuf==0  & sub_M<400, noconstant robust
 estadd scalar obs = 177
 
 
  predict resid_predict, r
 
 g v2_v1_r = v2_v1 + resid_v1 
 g v2_predict_r = v2_predict + resid_predict

 
preserve
 keep if ru_limit==1 & n==1 & manuf==0 & sub_M<400
 corr v2_v1 v2_predict
 corr v2_predict_r v2_v1_r
 corr v2_predict_noz v2_v1_noz
 
 g x = 0 in 1
 replace x = 300 in 175
 
 twoway (scatter v2_v1 v2_predict, m(oh) ) (line x x, lpattern(dash)), xlabel(0(50)300) ylabel(0(50)300) ///
 ytitle("predicted using winning characteristics ({c $|}M)") ///
 xtitle("predicted using runner-up characteristics  ({c $|}M)") ///
 legend(off) 
 graph export $appxdir/altspec_v2_serv.eps, replace
 // the outlier has over $5B in investment planned... 

 replace x = 150 in 175
 
  twoway (scatter v2_v1_noz v2_predict_noz, m(oh) ) (line x x, lpattern(dash)), xlabel(0(25)150) ///
  ylabel(0(25)150) ///
 ytitle("predicted using winning characteristics ({c $|}M)") ///
 xtitle("predicted using runner-up characteristics  ({c $|}M)") ///
 legend(off)
  graph export $appxdir/altspec_v2_noz_serv.eps, replace 
 
  
restore

esttab using "$appxdir/OLS_serv_altspec.tex", replace ///
		cells(b(star fmt(%-10.2fc)) & se(par fmt(%-10.2fc))) ///
		stats(obs r2 , fmt(%9.0fc %-10.3fc )	///
		labels( "Observations" "R-squared"))	///
		collabels(none) mlabels(none) label ///
		keep(diff_corp_tax diff_income_tax c.diff_income_tax#c.jobs_direct /// 
		diff_proptax /// 
		 0.low_serv#c.diff_incwage_top_5 1.low_serv#c.diff_incwage_top_5  diff_e_comm ///
		diff_FHFA c.diff_FHFA#c.invest_B /// 
		diff_r2w   /// 
		diff_auto_roadnetwork   ///
		1.trade#c.diff_airport_any  ///
	1.trade#c.diff_top_RD 0.trade#c.diff_top_RD ///
		jobs_direct invest_B mult_total income_tax corp_tax sales_tax proptax term_limit ln_pinc  /// 
		incwage_top_5 unemp v2_predict ) ///
		order(diff_corp_tax diff_income_tax c.diff_income_tax#c.jobs_direct /// 
		diff_proptax /// 
		 0.low_serv#c.diff_incwage_top_5 1.low_serv#c.diff_incwage_top_5  diff_e_comm  ///
		diff_FHFA c.diff_FHFA#c.invest_B /// 
		diff_r2w   /// 
		diff_auto_roadnetwork  ///
		1.trade#c.diff_airport_any   ///
		1.trade#c.diff_top_RD 0.trade#c.diff_top_RD ///
		v2_predict  ///
		jobs_direct invest_B  mult_total income_tax corp_tax sales_tax proptax term_limit unemp /// 	
		ln_pinc incwage_top_5  ) ///
			refcat(diff_corp_tax "\textbf{Profit Function:}" ///
		v2_predict "\textbf{Valuation:}" , nolabel)		 alignment(r) ///
		varlabels( c.diff_income_tax#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ///
			0.low_serv#c.diff_incwage_top_5 "$\Delta$ Industry Wage (\\$1,000) $\times$ High-Skill Services" ///
			1.low_serv#c.diff_incwage_top_5 "$\Delta$ Industry Wage (\\$1,000) $\times$ Trade and Other Services" ///
			c.diff_FHFA#c.invest_B  "\hspace{4mm} $\times$ Investment Planned (\\$ B)"  ///
			1.trade#c.diff_airport_any "$\Delta$ Large Airport $\times$ Trade"  ///
			1.trade#c.diff_top_RD "$\Delta$ Research University $\times$ Trade" ///
			0.trade#c.diff_top_RD "$\Delta$ Research University $\times$ Services" ///
			v2_predict "Runner-up Valuation Predicted using Spec (2)")

********************************************************************************
* FIG L.2 
********************************************************************************
insheet using $datadir/runner_up_correlations_serv_altspec.csv, comma clear

keep v2 v6 
rename v2 profits_ru_cond
rename v6 v_ru_cond_resid
g manuf=0

sa $temp/ru_serv, replace

insheet using $datadir/runner_up_correlations_altspec.csv, comma clear

keep v2 v6 
rename v2 profits_ru_cond
rename v6 v_ru_cond_resid
g manuf=1 

append using $temp/ru_serv 

binscatter profits v if manuf==0 & v>0, m(oh) lcol(gray) xtitle("Valuation ({c $|}M)") ytitle("Profits ({c $|}M)")
		graph export $appxdir/bs_serv_altspec.eps, replace
		
binscatter profits v if manuf==1, m(oh) lcol(gray) xtitle("Valuation ({c $|}M)") ytitle("Profits ({c $|}M)")
		graph export $appxdir/bs_manuf_altspec.eps, replace
********************************************************************************
* TABLE L.3 
********************************************************************************
insheet using $datadir/mle_coef_manuf_altspec.csv, comma clear 

format estimate stderror %12.2fc 

g label = "$\Delta$ Corporate Tax (\%)" if v1=="diff_corp_tax"
g order = 1 if v1=="diff_corp_tax"
replace label ="\hspace{4mm} $\times$ Investment Planned (\\$ B)" if v1=="diff_corp_tax:invest_B"
replace order = 2  if v1=="diff_corp_tax:invest_B"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_corp_tax"
replace order = 3 if v1=="sigma_diff_corp_tax"

replace label = "$\Delta$ Income Tax (\%)" if v1=="diff_income_tax"
replace order = 5 if v1=="diff_income_tax"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_income_tax"
replace order = 6 if v1=="sigma_diff_income_tax"

replace label ="$\Delta$ Property Tax (\%)" if v1=="diff_proptax"
replace order = 7 if v1=="diff_proptax"

replace label  ="$\Delta$ Industry Wage (\\$1,000)" if v1=="diff_wage"
replace order = 8  if v1=="diff_wage"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_wage" 
replace order = 9 if v1=="sigma_diff_wage" 

replace label = "$\Delta$ Electricity Price (c/KwH) $\times$ Investment Planned (\\$ B)" if v1=="invest_B:diff_e_ind" 
replace order = 10 if v1=="invest_B:diff_e_ind" 
replace label = "$\Delta$ Industrial Land Supply $\times$ Investment Planned (\\$ B)" if v1=="invest_B:diff_indus_zoning" 
replace order = 11 if v1=="invest_B:diff_indus_zoning" 
replace label = "$\Delta$ Auto Network Density $\times$ Traditional Manufacturing " if v1=="manuf_type_3:diff_auto_roadnetwork"
replace order = 12 if v1=="manuf_type_3:diff_auto_roadnetwork"

replace label = "$\Delta$ Population with BA+ (\%) $\times$ High-Tech Manufacturing" if v1=="diff_pr_college:manuf_type_1"
replace label =  "$\Delta$ Population with BA+ (\%) $\times$ Traditional Manufacturing" if v1=="diff_pr_college:manuf_type_3"
replace order = 13 if v1=="diff_pr_college:manuf_type_1"
replace order = 14 if v1=="diff_pr_college:manuf_type_3"

replace label = "$\Delta$ Population in Relevant Occupations (1,000)" if v1=="diff_occ_top2_naics3" 
replace label =  "\hspace{4mm} $\times$ Jobs Promised (1,000)"  if v1=="diff_occ_top2_naics3:jobs_direct" 
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_occ_top2_naics3"
replace order = 15 if v1=="diff_occ_top2_naics3" 
replace order = 16 if v1=="diff_occ_top2_naics3:jobs_direct" 
replace order = 17  if v1=="sigma_diff_occ_top2_naics3"

replace label ="$\Delta$ Industry Estab. Share (\%) $\times$ High-Tech Manufacturing " if v1=="manuf_type_1:diff_perc_est_n4"
replace order = 18 if v1=="manuf_type_1:diff_perc_est_n4"

replace label = "Jobs Promised (1,000)" if v1=="jobs_direct"
replace label = "Investment Planned (\\$ B)" if v1=="invest_B"
replace label = "Indirect Jobs (Jobs $\times$ Multiplier)" if v1=="mult_jobs"
replace label = "Corporate Tax (\%)" if v1=="corp_tax"
replace label = "Income Tax (\%)" if v1=="income_tax"
replace label = "Term Limit"  if v1=="term_limit"
replace label = "Log(Income per capita)" if v1=="ln_pinc"
replace label = "Relevant Occupation Wage (\\$1,000)" if v1=="incwage_top_5"
replace label = "Relevant Occupation Wage $\times$ Log(Income per capita)" if v1=="incwage_top_5:ln_pinc"
replace label = "Unemployment (\%)" if v1=="unemp"
replace label = "Unemployment $\times$ Jobs Promised" if v1=="jobs_direct:unemp"

replace order = 19 if v1=="predict_v2"
replace label = "Predicted Runner-up Valuation" if v1=="predict_v2"
replace order = 20 if v1=="sigma" 
replace label = "$\sigma$" if v1=="sigma"


sort order 
g pi = (order<=18)

	* MAKE TABLE
	g tab = "\begin{tabular}{lrr}" in 1
	g top = "\toprule" in 1
	g hline = " \hline" in 1 
	g bot = "\bottomrule" in 1
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "Variable & Estimate & Std. Error \\ " in 1
	g profits= "\textit{Profits:} &&	\\  " in 1
	g valuation= "\textit{Valuation:} &&	\\  " in 1
	g c = " "

*****Output
	local filename = "mle_manuf_results_altspec"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex profits if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==1 ///
				, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex valuation if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==0 ///
				, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
********************************************************************************
* TABLE L.4
********************************************************************************
		insheet using $datadir/mle_coef_serv_altspec.csv, comma clear 

format estimate stderror %12.2fc 

g label = "$\Delta$ Corporate Tax (\%)" if v1=="diff_corp_tax"
g order = 1 if v1=="diff_corp_tax"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_corp_tax"
replace order = 2 if v1=="sigma_diff_corp_tax"

replace label = "$\Delta$ Income Tax (\%)" if v1=="diff_income_tax"
replace order = 3 if v1=="diff_income_tax"
replace label ="\hspace{4mm} $\times$ Jobs Promised (1,000)" if v1=="diff_income_tax:jobs_direct"
replace order = 4 if v1=="diff_income_tax:jobs_direct"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_income_tax"
replace order = 5 if v1=="sigma_diff_income_tax"

replace label ="$\Delta$ Property Tax (\%)" if v1=="diff_proptax"
replace order = 6 if v1=="diff_proptax"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_proptax"
replace order = 7 if v1=="sigma_diff_proptax"

replace label  ="$\Delta$ Right-to-Work State" if v1=="diff_r2w"
replace order = 8  if v1=="diff_r2w"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_r2w" 
replace order = 9 if v1=="sigma_diff_r2w" 

replace label = "$\Delta$ Housing Price (\\$1,000)" if v1=="diff_FHFA"
replace order = 10 if v1=="diff_FHFA"
replace label = "\hspace{4mm} $\times$ Investment (\\$ B)" if v1=="diff_FHFA:invest_B"
replace order = 11 if v1=="diff_FHFA:invest_B"

replace label = "$\Delta$ Industry Wage (\\$1,000) $\times$ High-Skill Services" if v1=="diff_incwage_top_5:lowserv_0"
replace label = "$\Delta$ Industry Wage (\\$1,000) $\times$ Trade/Other Services" if v1=="diff_incwage_top_5:lowserv_1"
replace order = 12 if v1=="diff_incwage_top_5:lowserv_0"
replace order = 13 if v1=="diff_incwage_top_5:lowserv_1"

replace label = "$\Delta$ Commercial Electricity Price (c/KwH)" if v1=="diff_e_comm" 
replace order = 14  if v1=="diff_e_comm" 
replace label = "$\Delta$ Auto Network Density" if v1=="diff_auto_roadnetwork"
replace order = 15 if v1=="diff_auto_roadnetwork"
replace label = "$\Delta$ Large Airport $\times$ Trade" if v1=="diff_airport_any:trade_1"
replace order = 16 if v1=="diff_airport_any:trade_1"

replace label = "$\Delta$ Research University $\times$ Services" if v1=="diff_top_RD:trade_0"
replace label = "$\Delta$ Research University $\times$ Trade" if v1=="trade_1:diff_top_RD"
replace order = 17 if v1=="diff_top_RD:trade_0"
replace order = 18 if v1=="trade_1:diff_top_RD"

replace label = "Jobs Promised (1,000)" if v1=="jobs_direct"
replace label = "Investment Planned (\\$ B)" if v1=="invest_B"
replace label = "Industry Multiplier" if v1=="mult_total"
replace label = "Corporate Tax (\%)" if v1=="corp_tax"
replace label = "Income Tax (\%)" if v1=="income_tax"
replace label = "Sales Tax (\%)" if v1=="sales_tax"
replace label = "Property Tax (\%)" if v1=="proptax"
replace label = "Term Limit"  if v1=="term_limit"
replace label = "Log(Income per capita)" if v1=="ln_pinc"
replace label = "Relevant Occupation Wage (\\$1,000)" if v1=="incwage_top_5"
replace label = "Unemployment (\%)" if v1=="unemp"

replace order = 19 if v1=="predict_v2"
replace label = "Predicted Runner-up Valuation" if v1=="predict_v2"

replace order = 20 if v1=="sigma" 
replace label = "$\sigma$" if v1=="sigma"

sort order 
g pi = (order<=18)

	* MAKE TABLE
	g tab = "\begin{tabular}{lrr}" in 1
	g top = "\toprule" in 1
	g hline = " \hline" in 1 
	g bot = "\bottomrule" in 1
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "Variable & Estimate & Std. Error \\ " in 1
	g profits= "\textit{Profits:} &&	\\  " in 1
	g valuation= "\textit{Valuation:} &&	\\  " in 1
	g c = " "

*****Output
	local filename = "mle_serv_results_altspec"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex profits if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==1 ///
				, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex valuation if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==0 ///
				, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	

********************************************************************************
* TABLE L.5 
********************************************************************************
*simulated pi and v in winning places: 
insheet using $datadir/cf_locations_altspec.csv, comma clear 
keep if winner==1 
destring sub_m, force replace 
collapse (sum) mean_v mean_pi sub_m (p50) share
g type="real"
sa $temp/real_manuf, replace 

insheet using $datadir/cf_locations_serv_altspec.csv, comma clear 
keep if winner==1 
destring sub_m, force replace 
collapse (sum) mean_v mean_pi sub_m (p50) share
g type="real"
sa $temp/real_serv, replace 

append using $temp/real_manuf 
collapse (sum) mean_v mean_pi sub_m (mean) share , by(type)

rename mean_* * 
sa $temp/real, replace 
************************************************************
*simulated pi and v in counterfactual places: 
insheet using $datadir/cf_locations_altspec.csv, comma clear 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_manuf, replace 

insheet using $datadir/cf_locations_serv_altspec.csv, comma clear 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_serv, replace 

append using $temp/cf_manuf 
collapse (sum) adj_v adj_pi, by(type)
sa $temp/cf, replace 

rename adj_* *

append using $temp/real 

replace pi = pi/1000
replace v = v/1000
replace sub = sub/1000

g policy =  "Subsidy Ban" if type=="cf"
replace policy = "Competition" if type == "real"
drop type 
recode sub_ (.=0)

gsort -policy 
g state_payoff = v - sub
g firm_payoff = pi + sub
g total_welfare = v + pi 
g mover = 100-share

order policy v pi sub_m state_pay firm_payoff total 

set obs  3
foreach v in state_payoff firm_payoff total_welfare {
		replace `v' = 100*(`v'[2] - `v'[1])/(`v'[1]) in 3
}


	format mover v pi sub_m state_payoff firm_payoff total_welfare %12.1fc
	
g line3text = "\multicolumn{5}{r|}{\textit{$\Delta$ welfare from competition:}} "

tostring state_payoff firm_payoff total_welfare mover, force usedisplayformat replace 

foreach v in state_payoff firm_payoff total_welfare {
	replace `v' = `v' + "\%" in 3
}

replace mover = mover + "\%"
replace mover = "\multicolumn{1}{c|}{-}" if policy=="Subsidy Ban"
	
	* MAKE TABLE
	g tab = "\begin{tabular}{c|r|rr|r|rr|r}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

		g title1 = " & &  \multicolumn{2}{c|}{Simulated} & Sub  &  \multicolumn{2}{c|}{Payoffs (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c}{Total} \\ " in 1
		g title2 = "  \multicolumn{1}{c|}{Policy}& \multicolumn{1}{c|}{Movers}& \multicolumn{1}{c}{$ v $ (\\$ \hspace{-1mm}B)}   &  \multicolumn{1}{c|}{$\pi$ (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c|}{(\\$ \hspace{-1mm}B)}  & \multicolumn{1}{c}{States} & \multicolumn{1}{c|}{Firms}  & \multicolumn{1}{c}{Welfare} \\ " in 1

	g c = " "

*****Output
	local filename = "counter_v_altspec"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		 
	listtex policy mover v pi sub_m state_pay firm_payoff total if _n<3, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
		listtex line3text state_pay firm_payoff total if _n==3, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	